home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Spy / Spy Addition.c < prev    next >
C/C++ Source or Header  |  1995-09-10  |  4KB  |  147 lines

  1. #include <Palettes.h>
  2. #include <GestaltEqu.h>
  3. #include <Icons.h>
  4. #include <A4Stuff.h>
  5. #include "DS Additions.h"
  6. #include "Drag.h"
  7. #include <Components.h>
  8. #include <QuickTimeComponents.h>
  9. #include "Offscreen.h"
  10.  
  11.  
  12. #define ScreenDepth(gdh) ((*((*gdh)->gdPMap))->pixelSize)
  13.  
  14. struct {
  15.     Component    videoComponent;
  16.     ComponentInstance    videoInstance;
  17. };
  18.  
  19. pascal long main( DSAdditionParamBlockPtr params)
  20. {
  21.     long         result = 0;
  22.     Rect        localRect;
  23.     Point        mousePoint;
  24.     OSErr        theErr;
  25.     RGBColor    redColor, blueColor;
  26.     long        oldA4 = SetCurrentA4();
  27.     Component    comp;
  28.     ComponentInstance    ci;
  29.     ComponentDescription    looking;
  30.     VideoDigitizerComponent    vci;
  31.     GrafPtr    savePort;
  32.     VideoDigitizerError    error;
  33.     SGChannel    videoChannel;
  34.     GDHandle        gdh;
  35.     Rect            maxRect;
  36.     WindowOffscreen *offscreen;
  37.     
  38.     switch(params->dsMessage) {
  39.         /*
  40.             Given a draw message, draw what we need into the 
  41.             provided rectangle
  42.         */
  43.         case kMsgInitAddition:
  44.             params->dsRefCon = 0;
  45.             looking.componentType = videoDigitizerComponentType;
  46.             looking.componentSubType = 0;
  47.             looking.componentManufacturer = 0;
  48.             looking.componentFlags = 0;
  49.             looking.componentFlagsMask = 0;
  50.             comp = FindNextComponent(0, &looking);
  51.             if(comp) {    
  52.                 vci = (VideoDigitizerComponent)OpenComponent(comp);
  53.                 params->dsRefCon = (long)vci;
  54.             }    
  55.             result = (params->dsRefCon == 0);
  56.             break;
  57.  
  58.         case kMsgCloseAddition:
  59.             if(params->dsRefCon != nil) {
  60.                 CloseComponent((VideoDigitizerComponent)params->dsRefCon);
  61.             }
  62.             break;
  63.  
  64.         case kMsgDrawHilite:
  65.         case kMsgDraw:
  66.             localRect = params->dsLocalRect;
  67.             GetPort(&savePort);
  68.             error = 0;
  69.  
  70.             offscreen = nil;
  71.             if(params->dsRefCon != nil) {
  72.                 GetGWorld((CGrafPtr *)&savePort, &gdh);
  73.                 if(savePort == params->dsWindow) {
  74.                     gdh = nil;
  75.                 }
  76.                 if((savePort != params->dsWindow) && gdh) {
  77.                     error = VDGetMaxSrcRect((VideoDigitizerComponent)params->dsRefCon, 0, &maxRect);
  78.                     if(maxRect.right - maxRect.left < localRect.right - localRect.left){
  79.                         localRect.right = localRect.left + (maxRect.right - maxRect.left);
  80.                     }            
  81.                     if(maxRect.bottom - maxRect.top < localRect.bottom - localRect.top){
  82.                         localRect.bottom = localRect.top + (maxRect.bottom - maxRect.top);
  83.                     }            
  84.                     error = VDSetPlayThruDestination((VideoDigitizerComponent)params->dsRefCon, (*gdh)->gdPMap, &localRect, nil, nil);        
  85.                     if(!error) {
  86.                         error = VDSetDigitizerRect((VideoDigitizerComponent)params->dsRefCon, &localRect);
  87.                         if(!error) {
  88.                             error = VDGrabOneFrame((VideoDigitizerComponent)params->dsRefCon);
  89.                         }
  90.                     }
  91.                 }
  92.                 else{
  93.                     error = -2;
  94.                 }
  95.                 if(offscreen) {
  96.                     DrawOnscreen(offscreen);
  97.                 }
  98.             }
  99.             else {
  100.                 error = -1;
  101.             }
  102.             if(error) {
  103.                 PlotIconID(¶ms->dsIconRect, atHorizontalCenter + atBottom, ttDisabled, 200);
  104.             }
  105.             params->dsNextDrawTime = TickCount() + 5;    //Draw again in 5 seconds
  106.             break;
  107.  
  108.         /*
  109.             Given a hit message, do whatever we do when we are hit
  110.         */
  111.         case kMsgHit:
  112.             localRect = params->dsLocalRect;
  113.             GetMouse(&mousePoint);
  114.  
  115.             //Make sure that the user actually let go inside the rect
  116.             //before doing our thing.
  117.             while(StillDown() && PtInRect(mousePoint, &localRect)) {
  118.                 GetMouse(&mousePoint);
  119.             }
  120.  
  121.             if(!StillDown()) {
  122.                 SysBeep(10);    //Perhaps I should copy the image to the clipboard?  Maybe later.
  123.             }
  124.             break;
  125.  
  126.         /*
  127.             Given a drop message, pull the files out of the 
  128.             DragReference then do what you want with them.
  129.         */
  130.         case kMsgDropOccurred:
  131.             {
  132.                 unsigned short    items, index;
  133.  
  134.                 CountDragItems(params->dsDragReference, &items);
  135.                     for (index = 1; index <= items; index++) {
  136.                     SysBeep(10);
  137.                 }
  138.             }
  139.             break;
  140.  
  141.  
  142.     }
  143.     
  144.     SetA4(oldA4);
  145.     return result;
  146. }
  147.